import axios from "axios";

class Http {
  instance;

  constructor(config) {
    this.instance = axios.create(config);
    this.instance.interceptors.request.use(
      (config) => {
        return config;
      },
      (error) => {
        return Promise.reject(error);
      }
    );
    this.instance.interceptors.response.use(
      (res) => {
        if(res.status === 200){
            return res.data;
        }else{
            return Promise.reject(res);
        }
      },
      (error) => {
        return Promise.reject(error);
      }
    );
  }

  get(config) {
    return this.instance.request({ ...config, method: "GET" });
  }
  post(config) {
    return this.instance.request({ ...config, method: "POST" });
  }
  put(config) {
    return this.instance.request({ ...config, method: "PUT" });
  }
  delete(config) {
    return this.instance.request({ ...config, method: "DELETE" });
  }
}

export default Http;
